/**
 * 
 */
package com.xbang.attendance.web.action.system.setuphouse;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.xbang.attendance.entity.system.Region;
import com.xbang.attendance.entity.system.Warehouse;
import com.xbang.attendance.service.RegionService;
import com.xbang.attendance.service.SystemService;
import com.demo2do.lighturl.annotation.Action;
import com.xbang.core.struts.support.BaseActionSupport;
import com.xbang.core.struts.support.SearchActionSupport;

/**
 * @author dev.zhang
 * 
 */
public class WarehouseManager extends SearchActionSupport {

	private static final long serialVersionUID = 6843098369301424790L;

	private static final Log logger = LogFactory.getLog(WarehouseManager.class);

	private Integer id;
	@Autowired
	private SystemService systemService;

	@Autowired
	private RegionService regionService;
	private Warehouse warehouse;
	
	private List<Region> regions = new ArrayList<Region>();
	
	private List<Warehouse> chooseWarehouse = new ArrayList<Warehouse>();

	@Action("/system/setuphouse/add")
	public String add() throws Exception {
		regions = regionService.getAKZRegion();
		chooseWarehouse = systemService.getObjects(Warehouse.class);
		return "detail";
	}

	@Action("/system/setuphouse/${id}/edit")
	public String edit() throws Exception {
		warehouse = (Warehouse) systemService.getObject(Warehouse.class, id);
		chooseWarehouse = systemService.getObjects(Warehouse.class);
		regions = regionService.getAKZRegion();
		return "detail";
	}

	@Action("/system/setuphouse/${id}/delete")
	public String delete() throws Exception {
		if (id != null) {
			warehouse = (Warehouse) systemService.getObject(Warehouse.class, id);
			systemService.delete(warehouse);
		}
		return "r:/system/setuphouse/list";
	}

	@Action("/system/setuphouse/save")
	public String save() throws Exception {
		if (warehouse.getId() != null) {
			systemService.update(warehouse);
		} else {
			systemService.save(warehouse);
		}
	//	System.out.println(currPageId);
		return "r:/system/setuphouse/"+currPageId+"/index/";
	}
	
	@Override
	public void resetCustomerSearchCriteria() {
		// TODO Auto-generated method stub
		
	}

	/**
	 * @return the warehouse
	 */
	public Warehouse getWarehouse() {
		return warehouse;
	}

	/**
	 * @param warehouse
	 *            the warehouse to set
	 */
	public void setWarehouse(Warehouse warehouse) {
		this.warehouse = warehouse;
	}

	/**
	 * @param systemService
	 */
	public void setSystemService(SystemService systemService) {
		this.systemService = systemService;
	}

	/**
	 * @return the id
	 */
	public Integer getId() {
		return id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 * @return the regions
	 */
	public List<Region> getRegions() {
		return regions;
	}

	/**
	 * @param regions the regions to set
	 */
	public void setRegions(List<Region> regions) {
		this.regions = regions;
	}

	public List<Warehouse> getChooseWarehouse() {
		return chooseWarehouse;
	}

	public void setChooseWarehouse(List<Warehouse> chooseWarehouse) {
		this.chooseWarehouse = chooseWarehouse;
	}

	public SystemService getSystemService() {
		return systemService;
	}

}
